program HORSPOOL_18;

{$APPTYPE CONSOLE}

  var bc:array['a'..'z']of integer;

 procedure OUTPUT(T,p:string;ofset:integer);
   begin
     writeln(T);
     while ofset >0 do begin
                         write(' ');
                         dec(ofset);
                       end;
     writeln(p);
   end;



  procedure pre_bc(p:string);
      var i,m:integer;
          j:char;
    begin
      m := length(p);
      for j:='a' to 'z' do
        bc[j] := m;
      for i:=1 to m - 1 do
        bc[p[i]]:= m - i + 1;
    end;


  procedure HORSPOOL(T,p:string);
      var i,j,n,m:integer;
          c:char;
    begin
      (*
      preprocessing (from boer mur algoritm(14))
      *)
      pre_bc(p);


      (*
      searching
      *)
      n:= length(T);
      m:=length(p);

      j:=0;
      while (j<= n - m + 1) do
        begin
          c := T[j + m];
          if (p[m] = c) then
            begin
              i:=1;
              while (p[i] = T[j+i])and(i<m) do inc(i);
              if (i = m) then OUTPUT(T,p,j);

            end;
          inc(j,bc[T[i]]);
        end;
    end;


begin
 HORSPOOL('asdasdasdssasdaasddasdfasdasdsdasdasfgddas','asda');
 readln;
end.
